from typing import List

class Solution:
    def permuteUnique(self, nums: List[int]) -> List[List[int]]:
        def dfs(nums,size,path,res,used):

            if len(path)==size:
                if path not in res:
                    res.append(path[:])

                return
            for i in range(size):
                if not used[i]:
                    used[i] = True
                    path.append(nums[i])
                    dfs(nums,size,path,res,used)
                    used[i] = False
                    path.pop()
        size = len(nums)
        used = [False for _ in range(size)]
        path = list()
        res = list()

        dfs(nums,size,path,res,used)
        return res
    # 一个失败的方法
    def permuteUnique1(self, nums: List[int]) -> List[List[int]]:
        def dfs(nums,size,path,res,used,check_dict):
            if len(path)==size:
                if path not in res:
                    res.append(path[:])
                return
            for i in range(size):
                if not used[i] and check_dict[nums[i]] == False:
                    check_dict[nums[i]] = True
                    used[i] = True
                    path.append(nums[i])
                    dfs(nums,size,path,res,used,check_dict)
                    used[i] = False
                    check_dict[nums[i]] = False
                    path.pop()
        size = len(nums)
        used = [False for _ in range(size)]
        path = list()
        check_dict = dict()
        for i in nums:
            check_dict[i] = False
        print(check_dict)
        res = []
        dfs(nums,size,path,res,used,check_dict)
        return res
if __name__ == '__main__':
    nums = [1,1,3]
    solution = Solution()
    val = solution.permuteUnique(nums)
    print(val)